package com.shitou.shitouproduct.controller;


import java.util.Arrays;
import java.util.Map;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import com.shitou.shitouproduct.entity.BrandSellProductEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shitou.shitouproduct.service.BrandSellProductService;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;



/**
 * 该品牌售卖的商品统称
 *
 * @author shitouren
 * @email 3076767823@qq.com
 * @date 2023-03-15 16:36:34
 */
@RestController
@RequestMapping("shitouproduct/brandsellproduct")
public class BrandSellProductController {
    @Autowired
    private BrandSellProductService brandSellProductService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = brandSellProductService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public RespBean info(@PathVariable("id") Long id){
        BrandSellProductEntity brandSellProduct = brandSellProductService.getById(id);

        return RespBean.success().put("brandSellProduct", brandSellProduct);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody BrandSellProductEntity brandSellProduct){
        brandSellProductService.save(brandSellProduct);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody BrandSellProductEntity brandSellProduct){
        brandSellProductService.updateById(brandSellProduct);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] ids){
        brandSellProductService.removeByIds(Arrays.asList(ids));

        return RespBean.success();
    }



    /**
     * 通过品牌id获得品牌售卖商品
     * @param brandId
     * @return
     */
    @ApiOperation(value = "通过品牌的id，获取该品牌下当前售卖的商品种类，需要登陆校验")
    @CheckUserLogin
    @PostMapping("/sellProduct")
    public RespBean sellProduct(@RequestParam Long brandId, @RequestParam Long categoryId){
        return brandSellProductService.getSellProductByBrandId(brandId, categoryId);
    }

}
